package function;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-06-27
 * Time: 21:58
 */
public class AddBook implements IWork {
    @Override
    public void work(BookList bookList) {
        if(bookList.getBookSize() == bookList.getBooks().length) {
            System.out.println("存储空间已满");
        }

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入添加书籍的名字：");
        String name = sc.nextLine();
        System.out.println("请输入添加书籍的作者：");
        String author = sc.nextLine();
        System.out.println("请输入添加书籍的价格：");
        int price = sc.nextInt();
        System.out.println("请输入添加书籍的类型：");
        //清空缓冲区
        sc.nextLine();
        String type = sc.nextLine();

        int bookSize = bookList.getBookSize();
        bookList.getBooks()[bookSize] = new Book(name,author,price,type);
        bookList.setBookSize(bookSize + 1);
        System.out.println("添加成功");
    }
}
